﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using DAL;
using Models;

namespace BLL
{
    public class RemarkManager
    {
        RemarkService service = new RemarkService();
        public bool add(Remark remark)
        {
            return service.add(remark);
        }
        //查询商品评论
        public List<Remark> getpro(Remark remark)
        {
            List<Remark> remarks = new List<Remark>();
            SqlDataReader reader = service.getpro(remark);
            while (reader.Read())
            {
                remarks.Add(new Remark(
                    reader.GetInt32(0),
                    reader.GetString(1),
                    reader.GetString(2),
                    reader.GetString(3),
                    reader.GetInt32(4),
                    reader.GetInt32(5)
                    ));
            }
            DBhelper.Close();
            return remarks;
        }
        //查询个人评论
        public List<Remark> getuser(Remark remark)
        {
            List<Remark> remarks = new List<Remark>();
            SqlDataReader reader = service.getuser(remark);
            while (reader.Read())
            {
                remarks.Add(new Remark(
                    reader.GetInt32(0),
                    reader.GetString(1),
                    reader.GetString(2),
                    reader.GetString(3),
                    reader.GetInt32(4),
                    reader.GetInt32(5)
                    ));
            }
            DBhelper.Close();
            return remarks;
        }
        public List<Product> GetList2(int id)
        {
            List<Product> coll = new List<Product>();
            SqlDataReader reader = service.getbyid(id);
            while (reader.Read())
            {
                coll.Add(new Product(
                    reader.GetString(0),
                    reader.GetString(1),
                    reader.GetString(2)
                    ));
            }
            DBhelper.Close();
            return coll;
        }
        public List<Product> Getpro2(int id)
        {
            List<Product> coll = new List<Product>();
            SqlDataReader reader = service.getbypro(id);
            while (reader.Read())
            {
                coll.Add(new Product(
                    reader.GetString(0),
                    reader.GetString(1),
                    reader.GetString(2)
                    ));
            }
            DBhelper.Close();
            return coll;
        }
        public Remark remarkcount(int id)
        {
            Remark remark = null;
            SqlDataReader reader = service.remarkcount(id);
            while (reader.Read())
            {
                if (reader.IsDBNull(0))
                {
                    remark = new Remark(
                        0
                        );
                }
                else
                {
                    remark = new Remark(
                        reader.GetInt32(0)
                        );
                }
            }
            DBhelper.Close();
            return remark;
        }
    }
}
